from flask_restx import fields

response_format = {
    'resultValue': fields.Raw(description='接口返回的数据 '),
    'resultCode': fields.Integer(description='返回状态码 200表示成功 '),
    'resultHint': fields.String(description='返回的错误信息')
}


def success(data, msg="", code=200):
    return {'resultValue': data, 'resultCode': str(code), 'resultHint': msg}


def error(msg, code=500):
    return {'resultHint': msg, 'resultCode': str(code)}


def exception_error(e):
    return error(getattr(e, "description", getattr(e, "args", ['未知错误'])[0]), getattr(e, 'code', 500))
